/**
 * Copyright (c) 2008 Andrew Rapp. All rights reserved.
 *  
 * This file is part of XBee-API.
 *  
 * XBee-API is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * XBee-API is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with XBee-API.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.rapplogic.xbee.api.wpan;

import com.rapplogic.xbee.util.ByteUtils;

/**
 * Provides access to XBee's 8 Digital (0-7) and 6 Analog (0-5) IO pins
 * 
 * @author andrew
 *
 */
public class IoSample {

    private RxResponseIoSample parent;
    private Integer dioMsb;
    private Integer dioLsb;
    private Integer analog0;
    private Integer analog1;
    private Integer analog2;
    private Integer analog3;
    private Integer analog4;
    private Integer analog5;

    public IoSample(RxResponseIoSample parent) {
        this.parent = parent;
    }

    public void setDioMsb(Integer dioMsb) {
        this.dioMsb = dioMsb;
    }

    public void setDioMsb(int dioMsb) {
        this.dioMsb = new Integer(dioMsb);
    }

    public void setDioLsb(Integer dioLsb) {
        this.dioLsb = dioLsb;
    }

    public void setDioLsb(int dioLsb) {
        this.dioLsb = new Integer(dioLsb);
    }

    public Integer getDioMsb() {
        return dioMsb;
    }

    public Integer getDioLsb() {
        return dioLsb;
    }

    public Integer getAnalog0() {
        return analog0;
    }

    public void setAnalog0(Integer analog0) {
        this.analog0 = analog0;
    }

    public void setAnalog0(int analog0) {
        this.analog0 = new Integer(analog0);
    }

    public Integer getAnalog1() {
        return analog1;
    }

    public void setAnalog1(Integer analog1) {
        this.analog1 = analog1;
    }

    public void setAnalog1(int analog1) {
        this.analog1 = new Integer(analog1);
    }

    public Integer getAnalog2() {
        return analog2;
    }

    public void setAnalog2(Integer analog2) {
        this.analog2 = analog2;
    }

    public void setAnalog2(int analog2) {
        this.analog2 = new Integer(analog2);
    }

    public Integer getAnalog3() {
        return analog3;
    }

    public void setAnalog3(Integer analog3) {
        this.analog3 = analog3;
    }

    public void setAnalog3(int analog3) {
        this.analog3 = new Integer(analog3);
    }

    public Integer getAnalog4() {
        return analog4;
    }

    public void setAnalog4(Integer analog4) {
        this.analog4 = analog4;
    }

    public void setAnalog4(int analog4) {
        this.analog4 = new Integer(analog4);
    }

    public Integer getAnalog5() {
        return analog5;
    }

    public void setAnalog5(Integer analog5) {
        this.analog5 = analog5;
    }

    public void setAnalog5(int analog5) {
        this.analog5 = new Integer(analog5);
    }

    /**
     * Returns boolean value of DIO 0 pin
     * Returns null if DIO 0 is not enabled
     *
     * @return
     */
    public Boolean isD0On() {
        if (this.parent.isD0Enabled()) {
            return new Boolean(ByteUtils.getBit(dioLsb, 1));
        }
        return null;
    }

    public Boolean isD1On() {
        if (this.parent.isD1Enabled()) {
            return new Boolean(ByteUtils.getBit(dioLsb, 2));
        }

        return null;
    }

    public Boolean isD2On() {
        if (this.parent.isD2Enabled()) {
            return new Boolean(ByteUtils.getBit(dioLsb, 3));
        }

        return null;
    }

    public Boolean isD3On() {
        if (this.parent.isD3Enabled()) {
            return new Boolean(ByteUtils.getBit(dioLsb, 4));
        }

        return null;
    }

    public Boolean isD4On() {
        if (this.parent.isD4Enabled()) {
            return new Boolean(ByteUtils.getBit(dioLsb, 5));
        }

        return null;
    }

    public Boolean isD5On() {
        if (this.parent.isD5Enabled()) {
            return new Boolean(ByteUtils.getBit(dioLsb, 6));
        }

        return null;
    }

    public Boolean isD6On() {
        if (this.parent.isD6Enabled()) {
            return new Boolean(ByteUtils.getBit(dioLsb, 7));
        }

        return null;
    }

    public Boolean isD7On() {
        if (this.parent.isD7Enabled()) {
            return new Boolean(ByteUtils.getBit(dioLsb, 8));
        }

        return null;
    }

    public Boolean isD8On() {
        if (this.parent.isD8Enabled()) {
            return new Boolean(ByteUtils.getBit(dioMsb, 1));
        }

        return null;
    }

    public String toString() {
        return null;
    }
}